package com.yunkss.eftool.crypto.key;

import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.util.encoders.Hex;

/**
 * @author csx
 * @date 2022/2/18 8:28
 * @desc
 */

public class CisCodec {
    public CisCodec() {
    }

    public static String encodeToHexString(byte[] bytes) {
        return Hex.toHexString(bytes);
    }

    public static byte[] decodeFromHexString(String hexStr) {
        return Hex.decode(hexStr);
    }

    public static String hexStringToBase64String(String hexStr) {
        byte[] hexBytes = decodeFromHexString(hexStr);
        return Base64.encodeBase64String(hexBytes);
    }

    public static String base64StringToHexString(String base64Str) {
        byte[] base64Bytes = Base64.decodeBase64(base64Str);
        return encodeToHexString(base64Bytes);
    }

    public static byte[] decodeBase64String(String base64Str) {
        return Base64.decodeBase64(base64Str);
    }

    public static String toBase64String(String plainText) {
        return Base64.encodeBase64String(plainText.getBytes());
    }

    public static String binaryToBase64String(byte[] binaryData) {
        return Base64.encodeBase64String(binaryData);
    }
}
